
#ifndef _MEMBER_BLAYOUT_H_
#define _MEMBER_BLAYOUT_H_

#include <BSpring>
#include <BLayout>
#include <BSpacer>
#include <BWidget>

#define layout_member(layout)		((member_BLayout*)((BLayout*)layout)->_ptr)

namespace BWE
{
	struct CacheSize
	{
		BSize	metaSize;
		BSize	realSize;
		inline void operator = (const BSize& size)
		{
			metaSize = size;
			realSize = size;
		}
	};

	class LayoutItem
	{
	public:
		LayoutItem();
		LayoutItem(const LayoutItem& other);
		~LayoutItem();

		void clear();
		bool empty() const;
		void flush();

		bool prepare();
		bool prepare(int remain, int width, int height);
		void adjust(int x, int y, int w, int h);
		void adjust(const BRect& rect);

		void operator = (BWidget* widget);
		void operator = (BLayout* layout);
		void operator = (BSpacer* spacer);
		void operator = (BSpring* spring);

		bool operator == (const LayoutItem& other) const;
		bool operator == (const BObject* object) const;
		bool operator == (const BWidget* widget) const;
		bool operator == (const BLayout* layout) const;
		bool operator == (const BSpacer* spacer) const;
		bool operator == (const BSpring* spring) const;

		bool operator != (const LayoutItem& other) const;
		bool operator != (const BObject* object) const;
		bool operator != (const BWidget* widget) const;
		bool operator != (const BLayout* layout) const;
		bool operator != (const BSpacer* spacer) const;
		bool operator != (const BSpring* spring) const;

		BWidgetHolder	widget;
		BLayoutHolder	layout;
		BSpacerHolder	spacer;
		BSpringHolder	spring;
		BSizeStretch	stretch;
		BSizePolicy		policy;
		Align			align;

		bool			dirty;
		bool			ignored;
		BSize			size;
		BSize			minSize;
		BSize			maxSize;
		BSize			sizeHint;
		BSize			fixedSize;
		BSize			preferSize;
		BSizePolicy		sizePolicy;

		BRect			rect;
		BSize			realSize;
		BSize			baseSize;
		BRect			realRect;
		bool			finishWidth;
		bool			finishHeight;
	};

	class member_BLayout
	{
	public:
		member_BLayout(BLayout* layout);
		~member_BLayout();

		inline bool event(const BEvent& event)
		{
			return boss->event(event);
		}

		BLayout*		boss;
		BWidget*		host;
		PartFlag		part;
		BLayout*		parent;
		BMargin			margin;
		bool			splitable;
		bool			visible;
		LayoutItem		item;

		bool			dirty;
		BSizePolicy		sizePolicy;
		BSize			fixedSize;
		BSize			minSize;
		BSize			maxSize;
		BRect			rect;

	};
}

#endif
